home *** CD-ROM | disk | FTP | other *** search
/ Directorty Opus 5 - Magellan 2 / Opus 5 - Magellan 2.iso / Extras / D51_NUSource / Source / Routines / Pool.s < prev    next >
Text File  |  1995-09-27  |  7KB  |  305 lines

  1. ***************************************************************************************
  2. * Pooled Memory routines, Assembler versions.                                         *
  3. * Taken from "amiga_lib 40.14 (11/08/93)".                                            *
  4. *                                                                                     *
  5. * All of these routines will use the exec.library routines if OS 3 or above is        *
  6. * available. The routines will work with any version of AmigaOS from 1.2 onwards.     *
  7. *                                                                                     *
  8. * AsmCreatePool   newPool [a0] = (memFlags [d0],puddleSize [d1],threshSize [d2])      *
  9. * AsmDeletePool                  (poolHeader [a0])                                    *
  10. * AsmAllocPooled   memory [d0] = (poolHeader [a0],memSize [d0])                       *
  11. * AsmFreePooled                  (poolHeader [a0],memory [a1],memSize [d0])           *
  12. *                                                                                     *
  13. * See the autodocs for  exec  or  amiga_lib  for information on how they are used.    *
  14. *                                                                                     *
  15. * Conversion to source code (with slight additions and adaptations) by                *
  16. * Leo Davidson (Pot-Noodle / Gods'Gift Utilities).                                    *
  17. *                                                                                     *
  18. * I have also added routines called Leo#? which are identical, but also do a          *
  19. * "Move.l PoolHead(a5),a0" at the start of the routine.                               *
  20. ***************************************************************************************
  21.  
  22. ;Test_Pool_On_OS3    ; Use assembled pool routines, even with OS3?
  23.  
  24. ***************************************************************************************
  25.  
  26. AsmCreatePool
  27.     Move.l    (AbsExecBase).w,a6    Execbase MUST be in a6.
  28.     IFND    Test_Pool_On_OS3
  29.     Cmp.w    #39,$0014(a6)        -.
  30.     Bcs.s    AsmCreatePool_Routine     |- Use OS lib if v39+ available.
  31.     Jmp    _LVOCreatePool(a6)    -'
  32.     ENDC
  33.  
  34. AsmCreatePool_Routine
  35.     Sub.l    A0,A0
  36.     Cmp.l    D2,D1
  37.     Bcs.s    AsmCreatePooled_L1
  38.     Move.l    D0,-(SP)
  39.     MoveQ.l    #7,D0
  40.     Add.l    D0,D1
  41.     Not.b    D0
  42.     And.b    D0,D1
  43.     Move.l    D1,-(SP)
  44.     MoveQ.l    #0,D1
  45.     MoveQ.l    #$18,D0
  46.     Jsr    _LVOAllocMem(a6)
  47.     Move.l    (SP)+,D1
  48.     Move.l    (SP)+,A0
  49.     Tst.l    D0
  50.     Beq.s    AsmCreatePooled_L2
  51.     Exg    A0,D0
  52.     Move.l    A0,8(A0)
  53.     Addq.l    #4,A0
  54.     Clr.l    (A0)
  55.     Move.l    A0,-(A0)
  56.     Lea    12(A0),A1
  57.     Move.l    D0,(A1)+
  58.     Move.l    D1,(A1)+
  59.     Move.l    D2,(A1)+
  60. AsmCreatePooled_L1
  61.     Move.l    A0,D0
  62. AsmCreatePooled_L2
  63.     RTS
  64.  
  65. LeoDeletePool
  66.     Move.l    PoolHead(a5),a0
  67. AsmDeletePool
  68.     Move.l    (AbsExecBase).w,a6    Execbase MUST be in a6.
  69.     IFND    Test_Pool_On_OS3
  70.     Cmp.w    #39,$0014(a6)        -.
  71.     Bcs.s    AsmDeletePool_Routine     |- Use OS lib if v39+ available.
  72.     Jmp    _LVODeletePool(a6)    -'
  73.     ENDC
  74.  
  75. AsmDeletePool_Routine
  76.     Move.l    A0,D0
  77.     Beq.s    AsmDeletePool_L1
  78.     MoveM.l    D2/A2,-(SP)
  79.     Move.l    (A0),A2
  80. AsmDeletePool_L2
  81.     Move.l    (A2),D2
  82.     Beq.s    AsmDeletePool_L3
  83.     Move.l    A2,A1
  84.     Move.l    D2,A2
  85.     Move.l    -(A1),D0
  86.     Jsr    _LVOFreeMem(a6)
  87.     Bra.s    AsmDeletePool_L2
  88.  
  89. AsmDeletePool_L1
  90.     RTS
  91.  
  92. AsmDeletePool_L3
  93.     Move.l    A2,A1
  94.     Subq.l    #4,A1
  95.     MoveM.l    (SP)+,D2/A2
  96.     MoveQ.l    #$18,D0
  97.     Jmp    _LVOFreeMem(a6)
  98.  
  99. LeoAllocPooled
  100.     Move.l    PoolHead(a5),a0
  101. AsmAllocPooled
  102.     Move.l    (AbsExecBase).w,a6    Execbase MUST be in a6.
  103.     IFND    Test_Pool_On_OS3
  104.     Cmp.w    #39,$0014(a6)        -.
  105.     Bcs.s    AsmAllocPooled_Routine     |- Use OS lib if v39+ available.
  106.     Jmp    _LVOAllocPooled(a6)    -'
  107.     ENDC
  108.  
  109. AsmAllocPooled_Routine
  110.     Move.l    D0,D1
  111.     Beq.s    AsmAllocPooled_L1
  112.     Move.l    A0,D0
  113.     Beq.s    AsmAllocPooled_L1
  114.     MoveM.l    D2/D3/A2/A3,-(SP)
  115.     Move.l    D1,D2
  116.     Move.l    A0,A2
  117.     Cmp.l    $0014(A2),D2
  118.     Bcc.s    AsmAllocPooled_L2
  119. AsmAllocPooled_L3
  120.     Move.l    (A2),D3
  121. AsmAllocPooled_L4
  122.     Move.l    D3,A3
  123.     Move.l    (A3),D3
  124.     Beq.s    AsmAllocPooled_L5
  125.     Move.l    A3,A0
  126.     Tst.l    8(A0)
  127.     Beq.s    AsmAllocPooled_L5
  128.     Move.l    D2,D0
  129.     Jsr    _LVOAllocate(a6)
  130.     Tst.l    D0
  131.     Beq.s    AsmAllocPooled_L4
  132.     Move.l    D0,A0
  133.     Move.l    12(A2),D0
  134.     BTst    #$10,D0
  135.     Beq.s    AsmAllocPooled_L6
  136.     Move.l    A0,A1
  137.     Move.l    D2,D1
  138.     Addq.l    #7,D1
  139.     Lsr.l    #3,D1
  140.     Subq.l    #1,D1
  141.     Move.w    D1,D0
  142.     SWAP    D1
  143.     MoveQ.l    #0,D3
  144. AsmAllocPooled_L7
  145.     Move.l    D3,(A1)+
  146.     Move.l    D3,(A1)+
  147.     DBra    D0,AsmAllocPooled_L7
  148.     DBra    D1,AsmAllocPooled_L7
  149. AsmAllocPooled_L6
  150.     Move.l    A0,D0
  151. AsmAllocPooled_L8
  152.     MoveM.l    (SP)+,D2/D3/A2/A3
  153. AsmAllocPooled_L1
  154.     RTS
  155.  
  156. AsmAllocPooled_L2
  157.     Move.l    D2,D0
  158.     Addq.l    #8,D0
  159.     Addq.l    #4,D0
  160.     Move.l    12(A2),D1
  161.     Bsr    AsmAllocPooled_L9
  162.     Tst.l    D0
  163.     Beq.s    AsmAllocPooled_L8
  164.     Move.l    D0,A1
  165.     Move.l    A2,A0
  166.     Addq.l    #4,A0
  167.     Move.l    4(A0),D0
  168.     Move.l    A1,4(A0)
  169.     Exg    A0,D0
  170.     MoveM.l    D0/A0,(A1)
  171.     Move.l    A1,(A0)
  172.     Addq.l    #8,A1
  173.     Clr.l    (A1)+
  174.     Move.l    A1,D0
  175.     Bra.s    AsmAllocPooled_L8
  176.  
  177. AsmAllocPooled_L5
  178.     Move.l    12(A2),D1
  179.     Move.l    $0010(A2),D0
  180.     Add.l    #$00000024,D0
  181.     Bsr.s    AsmAllocPooled_L9
  182.     Tst.l    D0
  183.     Beq.s    AsmAllocPooled_L8
  184.     Move.l    D0,A3
  185.     Move.l    D0,A1
  186.     Move.l    A2,A0
  187.     Move.l    (A0),D0
  188.     Move.l    A1,(A0)
  189.     MoveM.l    D0/A0,(A1)
  190.     Move.l    D0,A0
  191.     Move.l    A1,4(A0)
  192.     MoveQ.l    #10,D0
  193.     Move.b    D0,8(A3)
  194.     Move.b    D0,9(A3)
  195.     Lea    Pool.MSG(PC),A0
  196.     Move.l    A0,10(A3)
  197.     Move.l    12(A2),D1
  198.     Move.w    D1,14(A3)
  199.     Lea    $0024(A3),A0
  200.     MoveQ.l    #7,D1
  201.     Not.l    D1
  202.     Move.l    A0,D0
  203.     And.l    D0,D1
  204.     Move.l    D1,A0
  205.     Move.l    $0010(A2),D0
  206.     Move.l    A0,$0010(A3)
  207.     Move.l    A0,$0014(A3)
  208.     Move.l    D0,$001C(A3)
  209.     Clr.l    (A0)
  210.     Move.l    D0,4(A0)
  211.     Add.l    D0,A0
  212.     Move.l    A0,$0018(A3)
  213.     Bra    AsmAllocPooled_L3
  214.  
  215. AsmAllocPooled_L9
  216.     Addq.l    #4,D0
  217.     Move.l    D0,-(SP)
  218.     Jsr    _LVOAllocMem(a6)
  219.     Tst.l    D0
  220.     Beq.s    AsmAllocPooled_L10
  221.     Move.l    D0,A0
  222.     Move.l    (SP),(A0)+
  223.     Move.l    A0,D0
  224. AsmAllocPooled_L10
  225.     Addq.l    #4,SP
  226.     RTS
  227.  
  228. LeoFreePooled
  229.     Move.l    PoolHead(a5),a0
  230. AsmFreePooled
  231.     Move.l    (AbsExecBase).w,a6    Execbase MUST be in a6.
  232.     IFND    Test_Pool_On_OS3
  233.     Cmp.w    #39,$0014(a6)        -.
  234.     Bcs.s    AsmFreePooled_Routine     |- Use OS lib if v39+ available.
  235.     Jmp    _LVOFreePooled(a6)    -'
  236.     ENDC
  237.  
  238. AsmFreePooled_Routine
  239.     Move.l    A0,D1
  240.     Beq.s    AsmFreePooled_L1
  241.     Move.l    A1,D1
  242.     Beq.s    AsmFreePooled_L1
  243.     Cmp.l    $0014(A0),D0
  244.     Bcc.s    AsmFreePooled_L2
  245.     Move.l    A3,-(SP)
  246.     Move.l    (A0),D1
  247. AsmFreePooled_L3
  248.     Move.l    D1,A3
  249.     Move.l    (A3),D1
  250.     Beq.s    AsmFreePooled_L4
  251.     Tst.l    8(A3)
  252.     Beq.s    AsmFreePooled_L4
  253.     Cmp.l    $0014(A3),A1
  254.     Bcs.s    AsmFreePooled_L3
  255.     Cmp.l    $0018(A3),A1
  256.     Bcc.s    AsmFreePooled_L3
  257.     Move.l    A3,A0
  258.     Jsr    _LVODeallocate(a6)
  259.     Move.l    4(A3),A1
  260.     Move.l    4(A1),D1
  261.     Beq.s    AsmFreePooled_L5
  262.     Move.l    D1,A0
  263.     Move.l    A3,(A0)
  264.     Move.l    A0,4(A3)
  265.     Move.l    A3,4(A1)
  266.     Move.l    (A3),A0
  267.     Move.l    A0,(A1)
  268.     Move.l    A1,4(A0)
  269.     Move.l    A1,(A3)
  270. AsmFreePooled_L5
  271.     Move.l    A3,A1
  272.     Move.l    (SP)+,A3
  273.     Move.l    $0020(A1),D0
  274.     Add.l    $0014(A1),D0
  275.     Sub.l    $0018(A1),D0
  276.     Beq.s    AsmFreePooled_L6
  277. AsmFreePooled_L1
  278.     RTS
  279.  
  280. AsmFreePooled_L2
  281.     Subq.l    #4,A1
  282.     Subq.l    #8,A1
  283. AsmFreePooled_L6
  284.     Move.l    A1,D0
  285.     Move.l    (A1)+,A0
  286.     Move.l    (A1),A1
  287.     Move.l    A0,(A1)
  288.     Move.l    A1,4(A0)
  289.     Move.l    D0,A1
  290.     Move.l    -(A1),D0
  291.     Jmp    _LVOFreeMem(a6)
  292.  
  293. AsmFreePooled_L4
  294.     Move.l    (SP)+,A3
  295.     Move.l    D7,-(SP)
  296.     Move.l    #$0100000F,D7
  297.     Jsr    _LVOAlert(a6)
  298.     Move.l    (SP)+,D7
  299.     RTS
  300.  
  301.     Dc.b    0
  302. Pool.MSG
  303.     Dc.b    'Pool',0
  304.     Even
  305.